package com.uwo.house.service.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.uwo.house.beans.request.SupervisionReportReq;
import com.uwo.house.dao.SupervisionReportDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.uwo.house.beans.request.BindSupervisionReq;
import com.uwo.house.beans.request.SupervisionSearchReq;
import com.uwo.house.beans.response.SupervisionOrderResp;
import com.uwo.house.dao.SupervisionOrderDao;
import com.uwo.house.service.ISupervisionService;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SupervisionService implements ISupervisionService {
	@Autowired
	private SupervisionOrderDao supervisionOrderDao;

	@Autowired
	private SupervisionReportDao supervisionReportDao;


	public List<SupervisionOrderResp> getSupervisionOrderSelective(SupervisionSearchReq supervisionSearchReq) {
		return supervisionOrderDao.selectSupervisionOrder(supervisionSearchReq);
	}

	public void bindSupervisionOrder(BindSupervisionReq supervision) {
		supervisionOrderDao.insertSupervisionOrder(supervision);
	}

	/*老方法
	public Map<String, Object> getSupervisionOrderSelective(
			SupervisionSearchReq searchFilter) {
		searchFilter.setOffset();
		searchFilter.setLimit();
		List<SupervisionOrderResp> list = supervisionOrderDao.selectSupervisionOrder(searchFilter);
		int count = supervisionOrderDao.countSupervisionOrder(searchFilter);
		
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("result", list);
		result.put("count", count);
		return result;
	}*/

	//监理人员上传我的报告
	public int insertReport(SupervisionReportReq supervisionReportReq) {
		return supervisionReportDao.insertReport(supervisionReportReq);
	}

	@Transactional
	public int updateStatus(String orderId,String supervisorId) {
		int result = 0;
		int result1 = supervisionOrderDao.updateSupervisionStatus(orderId, supervisorId);
		int result2 = supervisionReportDao.updateSupervisionReportStatus(orderId, supervisorId);
		if (result1 > 0 && result2 > 0) {
			result = 1;
		}
		return result;
	}
	//监理人员显示报告详情
	public List<SupervisionReportReq> getReport(String orderId,String supervisorId) {
		return supervisionReportDao.getReport(orderId,supervisorId);
	}

}
